<template>
  <h1>{{ sum }}</h1>
  <button @click="sum++">点我++</button>
  <hr />
  <h1>姓名：{{ name }}</h1>
  <h1>年龄：{{ age }}</h1>
  <h1>薪资：{{ job.j1.salary }}w</h1>
  <h1 v-show="person.car">座驾：{{ person.car }}</h1>
  <button @click="name += '~'">增加波浪线</button>
  <button @click="age++">增长年龄</button>
  <button @click="job.j1.salary++">加薪</button>
  <button @click="showRawPerson">输出原始的person</button>
  <button @click="addCar">给人添加一台车</button>
  <button @click="person.car.name += '@'">换车名</button>
</template>

<script>
import { ref, reactive, toRefs, toRaw, markRaw } from "vue";

export default {
  name: "Demo",
  setup() {
    let sum = ref(0);

    let person = reactive({
      name: "李文泰",
      age: 20,
      job: {
        j1: {
          salary: "20",
        },
      },
    });

    function showRawPerson() {
      console.log(toRaw(person));
    }

    function addCar() {
      const car = { name: "宝马", price: "50W" };
      person.car = markRaw(car);
    }

    //返回对象
    return { sum, ...toRefs(person), showRawPerson, addCar, person };
  },
};
</script>

<style>
</style>
